package com.lc.hongtai.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.lc.hongtai.MyApplication;
import com.lc.hongtai.R;
import com.lc.hongtai.conn.JsonWithdrawlog;
import com.zcx.helper.bound.BoundViewHelper;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 3/9/2016.
 */
public class WithDrawAdapter2 extends RecyclerView.Adapter<WithDrawAdapter2.ViewHolder> {


    private Context context;
    private int flag = 0;
    private List<Object> list;

    public WithDrawAdapter2(Context context, int flag, List<Object> list) {
        this.context = context;
        this.flag = flag;
        this.list = list;
    }


    public static class ViewHolder extends RecyclerView.ViewHolder {

        @Bind(R.id.tv_name)
        TextView tvName;
        @Bind(R.id.tv_time)
        TextView tvTime;

        @Bind(R.id.tv_02)
        TextView tv02;
        @Bind(R.id.text_status)
        TextView text_status;

        public ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = BoundViewHelper.boundView(this, MyApplication.scaleScreenHelper.loadView((ViewGroup) LayoutInflater.from(parent.getContext())
                .inflate(R.layout.list_05_item_withdraw, null)));

        ViewHolder vh = new ViewHolder(view);
        return vh;
    }


    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {

        final String status = ((JsonWithdrawlog.Info.ListContent) list.get(position)).status;
        holder.tvName.setText(((JsonWithdrawlog.Info.ListContent) list.get(position)).remark);
        holder.tvTime.setVisibility(View.VISIBLE);
        holder.tvTime.setText(((JsonWithdrawlog.Info.ListContent) list.get(position)).add_time);
        holder.tv02.setText(((JsonWithdrawlog.Info.ListContent) list.get(position)).withdraw_money + "元");
        holder.tv02.setTextColor(ContextCompat.getColor(context, R.color.colorYellow));

        String str_statur = ((JsonWithdrawlog.Info.ListContent) list.get(position)).withdraw_status;
        if (str_statur.equals("0")) {
            holder.text_status.setText("待审核");
            holder.text_status.setVisibility(View.GONE);
        } else if (str_statur.equals("1")) {
            holder.text_status.setVisibility(View.VISIBLE);
            holder.text_status.setText("申请提现");



        }

        holder.text_status.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //   Toast.makeText(context, "aaaaaaa", Toast.LENGTH_SHORT).show();
                String str = ((JsonWithdrawlog.Info.ListContent) list.get(position)).url;
                Intent intent = new Intent();

                intent.putExtra("url", str);
                intent.setClass(context, WithDrawWebActivity.class);
                context.startActivity(intent);
            }
        });
    }


    @Override
    public int getItemCount() {
        return list.size();
    }

}